<?php

namespace App\Repository;

use App\Entity\NoticeRead;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;

/**
 * @method NoticeRead|null find($id, $lockMode = null, $lockVersion = null)
 * @method NoticeRead|null findOneBy(array $criteria, array $orderBy = null)
 * @method NoticeRead[]    findAll()
 * @method NoticeRead[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
 */
class NoticeReadRepository extends ServiceEntityRepository {
    public function __construct (ManagerRegistry $registry) {
        parent::__construct($registry, NoticeRead::class);
    }

    /**
     * 获取用户已读消息ID集合
     * @param int $admin_user_id
     * @return array
     */
    public function getReadNoticesIds (int $admin_user_id) {
        $result = [];
        $objs = $this->createQueryBuilder('n')
            ->select('n.notice_id')
            ->andWhere('n.admin_user_id = :admin_user_id')
            ->setParameter('admin_user_id', $admin_user_id)
            ->getQuery()
            ->getResult();
        foreach ($objs as $obj) {
            array_push($result, $obj['notice_id']);
        }
        return $result;
    }
}
